
<template>
<el-form :model="ruleForm" style="width:40%;margin:0 auto;vertical-align: middle;vertical-align:middle;" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
 
  <el-form-item label="用户名" prop="name">
    <el-input v-model.number="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="pass">
    <el-input v-model.number="ruleForm.pass"></el-input>
  </el-form-item>
  <el-form-item   style="margin:50px auto 50px auto ;width:fit-content">
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    <el-button type="primary" @click="goregister" style="background:none;border-color:black;color:black;border-width:0">去注册</el-button>
  </el-form-item>
</el-form>
</template>

<script>
  export default {
    data() {
      var checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('用户名不能为空'));
        }else{
          callback();
        }
       
      };
       var checkPass = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('密码不能为空'));
        }
       else{
          callback();
        }
      };
      
      
      return {
        ruleForm: {
          name: '',
          pass: ''
        },
        rules: {
         
          name: [
            { validator: checkName, trigger: 'blur' }
          ],
          pass: [
            { validator: checkPass, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
       goregister(){
         this.$router.replace('/register')
       },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
             
             this.$router.replace('/index')
             
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>